import 'nprogress/nprogress.css';

import axios from 'axios';
import Nprogress from 'nprogress';

//实例对象
const instance = axios.create({
  baseURL: "http://kumanxuan1.f3322.net:8881/cms",
  timeout: 5000,
});
// 请求拦截器,请求之前
instance.interceptors.request.use(
  (config) => {
    Nprogress.start();
    let token = localStorage.getItem("x-auth-token");
    if (token) {
      config.headers["x-auth-token"] = token;
    }
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);
//响应拦截器，响应数据进入组件之前
instance.interceptors.response.use(
  (res) => {
    Nprogress.done();
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default instance;
